package com.hss.service.impl;

import com.hss.service.TestService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class TestServiceImpl implements TestService {
    @Override
    public BigDecimal test(Long id, Integer type) throws Exception {
        //假设金额是5000
        BigDecimal price = new BigDecimal("5000.00");
        if (type.equals(1)){
            //折扣券 是9折
            return   price.multiply(new BigDecimal("0.9"));
        }else if (type.equals(2)){
            //折扣券 是8折
            return   price.multiply(new BigDecimal("0.8"));
        }else if (type.equals(3)){
            //满减券
            BigDecimal price1 = new BigDecimal("3000.00");
            BigDecimal price2 = new BigDecimal("5000.00");
            if (price.compareTo(price2)>=0){
                return price.subtract(new BigDecimal("100")) ;
            }else {
                if (price.compareTo(price1)>=0){
                    return price.subtract(new BigDecimal("60")) ;
                }
            }
        }else {
            throw new Exception("折扣类型有误，请稍后再试");
        }
        return price;
    }
}
